<?php
/* SVN FILE: $Id: team.php 328 2010-07-21 11:00:00Z gregory.rome $ */
/**
 * Team Model.
 *
 * @todo Add file description.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright	 Copyright 2009-2010, Grégory Romé.
 * @link		  http://code.google.com/p/cbbweb/ cBBweb Project
 * @package	   cbbweb
 * @subpackage	cbbweb.models
 * @version	   $Revision: 328 $
 * @modifiedby	$LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-07-21 11:00:00 +0000 (Wed, 21 Jul 2010) $
 * @license	   http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Team Model.
 *
 * @todo Add model description.
 *
 * @package	   cbbweb
 * @subpackage	cbbweb.models
 */
class Team extends AppModel {

	var $name = 'Team';
	var $primaryKey = 'ID';
	var $useTable = 'team_listing';
	var $order = array("Team.strName COLLATE NOCASE" => "asc");

	/**
	 * belongsTo relationship.
	 *
	 * @var array
	 */
	var $belongsTo = array(
		'Race' => array(
			'className' => 'Race',
			'foreignKey' => 'idRaces',
			'fields' => array('Race.ID, Race.idStrings_Localized, Race.iRerollPrice')),
		'Coach' => array(
			'className' => 'Coach',
			'foreignKey' => 'idCoach',
			'fields' => array('Coach.ID, Coach.strName')));

	/**
	 * hasOne relationship.
	 *
	 * @var array
	 */
	var $hasOne = array(
		'StatisticsTeam' => array(
			'className'	 => 'StatisticsTeam',
			'foreignKey'	=> 'idTeam_Listing',
	  'dependent'=> true),
		'StatisticsCurrentSeasonTeam' => array(
			'className'   => 'StatisticsSeasonTeam',
			'foreignKey'  => 'idTeam_Listing',
			'conditions'	=> array('StatisticsCurrentSeasonTeam.bFinished' => 0),
			'dependent'=> false));

	/**
	 * hasMany relationship.
	 *
	 * @var array
	 */
	var $hasMany = array(
		'Player' => array(
			'className'	 => 'Player',
			'foreignKey'	=> 'idTeam_Listing',
			'dependent'=> true),
		'StatisticsSeasonTeam' => array(
			'className'	 => 'StatisticsSeasonTeam',
			'foreignKey'	=> 'idTeam_Listing',
			'dependent'=> true),
		'TeamRanking' => array(
			'className'	 => 'TeamRanking',
			'foreignKey'	=> 'idTeam_Listing',
			'dependent'=> true));

	/**
	 * hasAndBelongsToMany relationship.
	 *
	 * @var array
	 */
	var $hasAndBelongsToMany = array(
		'Championship' => array(
			'className' => 'Championship',
			'joinTable' => 'TeamRanking',
			'foreignKey' => 'idTeam_Listing',
			'associationForeignKey' => 'idRule_Listing',
			'unique' => true));

}
?>
